package com.example.demo.LeetCode.list;

public class ReversList {
    public static ListNode  revers(ListNode head){
        ListNode cur = head;
        ListNode pre = null;
        while (cur!=null){
            ListNode next = cur.next;
            cur.next = pre;
            pre = cur;
           cur = next;
        }
        return pre;
    }

    private static  ListNode createListNode1(){
        ListNode head1 = new ListNode(1);
        ListNode next1 = new ListNode(4);
        ListNode next2 = new ListNode(5);
        head1.next = next1;
        next1.next = next2;
        return head1;
    }

    public static void main(String[] args) {
        ListNode head = createListNode1();
        ListNode a = revers(head);
        while (a!=null){
            System.out.println(a.val);
            a = a.next;
        }
    }
}
